using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter09
{
	/// <summary>
	/// Example14: The Center of Mass of a Rod
	/// (A) Show that the center of mass of a rod of mass M and 
	/// length L lies midway between its ends, assuming the rod 
	/// gas a uniform mass per unit length.
	/// x_{cm} = L/2
	/// (B) Suppose a rod is nonuniform such that its mass per 
	/// unit length varies linearly with x according to the 
	/// expression \lambda = \alpha x, where \alpha is a constant. 
	/// Find the x coordinate of the center of mass as 
	/// a fraction of L.
	/// x_{cm} = 2/3*L
	/// </summary>
	public class Example14
	{
		public Example14()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Volume volume = new L.Volume();
			volume.XTo = 0.0;
			volume.XFrom = 1.0;
			volume.YTo = 0.0;
			volume.YFrom =0.001;
			volume.ZTo = 0.0;
			volume.ZFrom = 0.001;
			L.Scalar.FunctionOfPosition func = new L.Scalar.FunctionOfPosition(f);
			L.Density density = new L.Density();
            density.ScalarFunctionOfPosition = func;
			L.CenterOfMass xcm = new L.CenterOfMass(density, volume);
			result+=Convert.ToString(xcm.X);
		}
		private L.Scalar f(L.Position x)
		{
            L.Scalar s = new L.Scalar();
			double alpha = 10.0;
			s.Magnitude = alpha*x.X;
            return s;
		}
	}
}
